package com.zxc.config.dao;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.beans.PropertyVetoException;

/*
 * @Author: zxc of Russell
 * @Date: 2021/8/8 9:34
 * @Version 1.0
 *
 */
@Configuration
@MapperScan("com.zxc.o2o.dao")
public class DataSourceConfiguration {
    @Value(("${jdbc.driver}"))
    private String jdbcDriver;
    @Value(("${jdbc.url}"))
    private String jdbcUrl;
    @Value(("${jdbc.username}"))
    private String jdbcUsername;
    @Value("${jdbc.password}")
    private String jdbcPassword;

    /*
    * spring-dao.xml 对应的datasource
    * */
    @Bean(name = "dataSource")
    public DruidDataSource createDataSource(){
        //生成dataSource实例
        DruidDataSource dataSource = new DruidDataSource();
        //跟配置文件一样设置以下信息

        //驱动
        dataSource.setDriverClassName(jdbcDriver);
        //数据库连接URL
        dataSource.setUrl(jdbcUrl);
        //数据库用户名
        dataSource.setUsername(jdbcUsername);
        //数据库用户密码
        dataSource.setPassword(jdbcPassword);

        return dataSource;
    }
}
